package com.nys.cqhttp.message.factory.impl;

import java.util.Arrays;
import java.util.List;

import com.nys.cqhttp.model.Massage;
import org.springframework.web.client.RestTemplate;

import com.nys.cqhttp.message.factory.IMessageHandler;

import com.nys.cqhttp.param.Context;
import com.nys.cqhttp.util.SpringContextUtil;

/**
 * DirectUrlMessageHandler
 *
 * @author nysheng
 * @version 1.0.0
 * @description 毒鸡汤
 * @date 2021/12/28 19:53
 */

public class DuJiTangMessageHandler implements IMessageHandler {

    @Override
    public List<String> listHandler(Massage messagePojo, Context context) {
        return Arrays.asList(handler(messagePojo, context));
    }

    @Override
    public String handler(Massage messagePojo, Context context) {
        RestTemplate restTemplate = SpringContextUtil.getBean("restTemplate");
        try {
            return restTemplate.getForEntity(messagePojo.getValue(), String.class).getBody();
        }catch (Exception e){
            return null;
        }
    }
}
